"""
延时等待
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time


def rest(sec):
    time.sleep(sec)

if __name__ == '__main__':
    browser = webdriver.Chrome()
    # 创建 wait 对象, 最多等待 10 秒
    wait = WebDriverWait(browser, 10)
    url = 'https://www.jd.com/'
    browser.get(url)
    # 等到那个元素加载出来后, 返回辣个元素
    # presence_of_element_located 函数接收一个元组参数: (By.xx, 'xxx')
    input = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="key"]')))
    button = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="search"]/div/div[2]/button')))

    input.send_keys("kotlin")
    rest(1)
    button.click()
    rest(10)
    browser.close()

